<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	$settime=$this->session('settime');
	$return['params']=array(
		'order'=>'all',
	);
	$return['post']=array(
		'day'=>$settime['day']?:1,
		'intime'=>$settime['intime']?:date("Y-m-d"),
		'endtime'=>$settime['endtime']?:date("Y-m-d",strtotime("+1 day")),
	);
	$return['post']['settime']=array(
			'tstart'=>strtotime($return['post']['intime']),
			'tend'=>strtotime($return['post']['endtime']),
	);
	if(!empty($_RQ['keyword'])){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['title']=$post['params']['keyword'];
	}
	if(!empty($_RQ['province'])){
		$params['province']=$_RQ['province'];
		$return['params']['province']=$_RQ['params']['province'];
	}
	if(!empty($_RQ['city'])){
		$params['city']=$_RQ['city'];
		$return['params']['city']=$_RQ['params']['city'];
	}
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	$pindex = max(1, intval($post['page']));
	$psize = 15;
	$total='';
	$return['status']=0;
	if(!$post['keyword']){
		$return['list']=pdo_getslice('jy_jd_hotel',$params,array($pindex,$psize),$total,$fields,'','id desc');
		foreach($return['list'] as &$v){
			
			$price=pdo_getall('jy_jd_room',array('hotelid'=>$v['id']));
		
			$price=json_decode($price['0']['taocan'],true);
			
			if(is_array($price)){
				paixu($price,'price');
			}
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			$v['juli']=cfc('tools')->getdistance($post['lng'],$post['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
			$v['juli']=intval($v['juli']/1000);
			$v['price']=$price['0']['price'];
			
		}
		$_SESSION['hotellist']=$return['list'];
	}elseif($post['keyword']=='juli'){
		$return['status']=1;
		paixu($_SESSION['hotellist'],'juli','asc');
		$return['list']=$_SESSION['hotellist'];
		//print_r($return['list']);exit();
	}elseif($post['keyword']=='jiage'){
		$return['status']=2;
		paixu($_SESSION['hotellist'],'price','asc');
		$return['list']=$_SESSION['hotellist'];
	}else{
		$return['list']=pdo_getslice('jy_jd_hotel',$params,array($pindex,$psize),$total,$fields,'','id desc');
		foreach($return['list'] as &$v){			
			$price=pdo_getall('jy_jd_room',array('hotelid'=>$v['id']));		
			$price=json_decode($price['0']['taocan'],true);			
			if(is_array($price)){
				paixu($price,'price');
			}
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			$v['juli']=cfc('tools')->getdistance($post['lng'],$post['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
			$v['juli']=intval($v['juli']/1000);
			$v['price']=$price['0']['price'];
	}
	}
	exi($return);
}